<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/12/24 0024
  Time: 14:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>I级产品存储区域设置</title>
    <link rel="stylesheet" href="/bootstrap/bootstrap-5.3.3-dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/css/stock/a/set_storehouse.css" />
    <style type="text/css">

    </style>
</head>
<body>
<div class="panel product">
    <div class="panel-heading hhead">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <span style="color: blue;">您正在做的业务是：</span>
                <li class="breadcrumb-item"><a href="#">库存管理</a></li>
                <li class="breadcrumb-item"><a href="#">客户化设置</a></li>
                <li class="breadcrumb-item"><a href="#">库存地址分配设置</a></li>
                <li class="breadcrumb-item active" aria-current="page">I级产品存储区域设置</li>
            </ol>
        </nav>
    </div>
    <form id="searchForm">
        <input type="hidden" id="page" name="pageNum" value="1">
        <input type="hidden" id="pageSize" name="pageSize" value="5">
    </form>
    <div class="panel-body bbody">
        <table id="tab" >
            <thead>
            <tr style="background-color: #e8e8e8;">
                <td>I级产品分类</td>
                <td>库房名称</td>
                <td>存储区域名称</td>
                <td>分配</td>
                <td>释放</td>
            </tr>
            </thead>
            <tbody id="template" style="display: none">
                <tr>
                    <td class="firstName"></td>
                    <td class="warehouseName"></td>
                    <td class="firstAreaName"></td>
                    <td class="add"></td>
                    <td><a href="">释放</a></td>
                </tr>
            </tbody>
            <tbody id="firstTbl">

            </tbody>

        </table>
    </div>

    <div class="panel-footer ffooter">
        <div id="footerDiv" class="container-fluid">
            <div class="row">
                <label style="font-weight: 700;" class="col-sm-10">总数：<span style="color: red;" id="footNum1">5</span>例&nbsp;&nbsp;&nbsp;&nbsp;
                    当前第<span style="color: red;" id="pageNum1"></span>页&nbsp;&nbsp;&nbsp;&nbsp;
                    共<span style="color: red;" id="pagesNum1"></span>页&nbsp;&nbsp;&nbsp;&nbsp;
                </label>
                <nav aria-label="Page navigation example" class="col-sm-2">
                    <ul class="pagination">
                        <li class="page-item">
                            <a class="page-link" href="#" aria-label="Previous" id="a0">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <li class="page-item"><a class="page-link" href="#" id="a1">1</a></li>
                        <li class="page-item"><a class="page-link" href="#" id="a2">2</a></li>
                        <li class="page-item"><a class="page-link" href="#" id="a3">3</a></li>
                        <li class="page-item">
                            <a class="page-link" href="#" aria-label="Next" id="a4">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</div>


<div class="modal fade" id="proRegistraModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">
            <div class="modal-header">
                <h2>添加I级产品存储区域</h2>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <div id="bodyBox">
                        <form>
                            <table id="tbl">
                                <tr>
                                    <td class="col1">I级产品分类</td>
                                    <td class="col2" id="firstName"></td>
                                </tr>
                                <tr>
                                    <td class="col1">请选择库房</td>
                                    <td class="col2">
                                        <select>
                                            <option>请选择</option>
                                        </select>
                                    </td>
                                </tr>
                            </table>
                        </form>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button id="btnOK" class="btn btn-danger" data-bs-dismiss="modal">
                    提交<span class="glyphicon glyphicon-remove"></span>
                </button>
                <button id="btnConcel" class="btn btn-danger" data-bs-dismiss="modal">
                    关闭<span class="glyphicon glyphicon-remove"></span>
                </button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="/js/jquery-3.7.0.min.js"></script>
<script type="text/javascript" src="/bootstrap/bootstrap-5.3.3-dist/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript">
    $(function () {
        initFirstProducts(1);
    })

    function initFirstProducts(pageNum) {
        $("#page").val(pageNum);
        let json = formDateToJson("searchForm");
        $.ajax({
            url: "/s-first-product-area/initFirstProducts",
            type: "POST",
            data: json,
            contentType: "application/json",
            dataType: "json",
            success: function (data) {
                console.log(data);
                $("#footNum1").html(data.total);
                $("#pageNum1").html(pageNum);
                let pages = Math.ceil(data.total / 5);
                $("#pagesNum1").html(pages);
                params = {
                    "First": 1,
                    "Previous": data.current > 1 ? data.current - 1 : 1,
                    "Next": data.current < pages ? data.current + 1 : pages,
                    "Last": pages
                };
                console.log(params);

                $("#a0").attr("href", "javascript:initFirstProducts(" + params.First + ")")
                if(pageNum <= 2){
                    a1 = 1;
                    a2 = 2;
                    a3 = 3;
                }else if(pageNum >= pages - 1){
                    a1 = pageNum - 2;
                    a2 = pageNum - 1;
                    a3 = pageNum;
                }else {
                    a1 = pageNum - 1;
                    a2 = pageNum;
                    a3 = pageNum + 1;
                }
                $("#a1").attr("href", "javascript:initFirstProducts(" + a1 + ")")
                $("#a1").html(a1)
                a1 == pageNum? $("#a1").addClass("active") : $("#a1").removeClass("active")
                $("#a2").attr("href", "javascript:initFirstProducts(" + a2 + ")")
                $("#a2").html(a2)
                a2 == pageNum? $("#a2").addClass("active") : $("#a2").removeClass("active")
                a3 == pageNum? $("#a3").addClass("active") : $("#a3").removeClass("active")
                $("#a3").attr("href", "javascript:initFirstProducts(" + a3 + ")")
                $("#a3").html(a3)
                $("#a4").attr("href", "javascript:initFirstProducts(" + params.Last + ")")
                $("#firstTbl").empty();
                let template = $("#template").children();

                $.each(data.list, function (i, firstProduct) {
                    let tr = template.clone();
                    $.each(firstProduct,function (name,value) {
                        if(name=="warehouseId"){
                            if(value=='00'){
                                tr.find(".warehouseName").text();
                                let a='<a href="javascript:assignment(\'' + firstProduct['id'] + '\', \'' + firstProduct['firstName'] + '\')">分配</a>';
                                tr.find(".add").html(a);
                            }else {
                                tr.find(".warehouseName").text(firstProduct["swarehouseSetting"]["warehouseName"]);
                                tr.find(".add").text();
                            }
                        }else{
                            tr.find("." + name).text(value);
                        }
                    })
                    $("#firstTbl").append(tr);
                })

            }
        })
    }

    function assignment(id,firstName) {
        // alert(id);
        // alert(firstName);
        $("#proRegistraModal").modal("show");
        $("#firstName").text(firstName);
    }


</script>
</body>
</html>